# coding:utf8
import requests
from bs4 import BeautifulSoup
import re
import time
import sqlite3

url1 = "http://wsjs.saic.gov.cn/txnT01.do"
url2 = 'http://wsjs.saic.gov.cn/txnS01.do?locale=zh_CN&y7bRbP=KaobksVTJsVTJsVTqAP6E1LUP_6foA13bpNsesgwlOV'
url_last = ('http://wsjs.saic.gov.cn/txnS01.do?y7bRbp=qmMOquko3NL0kW5IwA7tVQPvKUzal3FFNLBj0XRC.Ai1f98FvSI7qMtnIkIpZnGmDyqEB44.m4t5PYUM2lEGpAeXTvHXE1UJG6MDNzchGZ.rmlc5h9UzTBKmm8rQ9HXeykQDEalgNY.LgGrq&c1K5tw0w6_=vuDfSO63VUQSyAUWX55A46qaWoW_1l8I5mukGsN20KULmKySEQ4mx4NsJNUT4nWvVjLaU.NZLcAIv4AGpugxvNm9vfcWe8KR.uGV5_k_aBPIbxH7_SpdvBRHPPdcTF4L')
url_f = 'http://wsjs.saic.gov.cn/txnRead02.ajax?MmEwMD=1Si3yIHkuAdLavTvDZYhKJua9KTrscZQDnzh.3UWfcA7i1Juk4t_Gpg9w2n9BtfHDV2_XeLfOjB0dcKLXYnV1u4mfnjcx6Ljdz1jUGSLLfwZHwHhSpascJ4kdS3m1X17Q71K0P53FVmdz9DknW.EjAIiVufChcCxbFSO8vsF6zKTxGOJqKeqJiigjoMmesShM9IMlqxc77GUEQrPNrps4fo1s1U3y7NjM82084ufFsRd_55lOv0udhAvTxseopns0YJ7SoIehONp21eItG0e7j.1NiBwxU5PnOCLNLeGsI7zQD6lm.kVjJsbMhJ0Bw4HhL4AWek41JyH79uVhx_yNkEGKVTCeHfh.m0hwpqnIgXhrO.TuxB_xH.G6EBOmht4cI.ZWhrdLsMVMEZ'

data = {'request:queryType':'',
    'request:queryAuto':'1',
    'request:queryMode':'1',
    'request:queryCom':'',	
    'request:mn':'颐麦坊',   	
    'request:ncs':'',
    'request:nc':'30',	
    'request:hnc':'',	
    'request:hne':'',	
    'request:sn':'',	
    'request:imf':'',	
    'request:maxHint':'',	
    'request:queryExp':'nc = 30 AND ( ((mncc = 颐麦坊) OR (mncc=?颐麦坊 OR mncc=颐?麦坊 OR mncc=颐麦?坊 OR mncc=颐麦坊?) OR (mncc=?麦坊 OR mncc=颐?坊 OR mncc=颐麦? OR mncc=?颐坊 OR mncc=麦?坊) OR (mncc=麦坊 OR mncc=颐坊 OR mncc=颐麦) OR (mncc=颐麦 OR mncc=麦坊 OR mncc=颐坊) OR (mncc=颐坊麦 OR mncc=麦颐坊 OR mncc=麦坊颐 OR mncc=坊颐麦 OR mncc=坊麦颐) OR (mncbc=颐麦坊)) OR mnoc=颐麦坊 )',
    'request:mi':'D3B954F268FF4B7484BDB4AA99C403CF',	
    'request:tlong':'apMT4CyEtcAFTRDtgtzzEQmadzteLV/5UggopczLPqMXYAPFhymvA2oc2X8sUFW5',	
    'attribute-node':'record_cache-flag:false',
    'attribute-node:record_start-row':'1',
    'attribute-node:record_page-row':'50',
    'attribute-node:record_sort-column':'RELEVANCE',
    'attribute-node:record_page':'1'
    }
headers = {
       'Host': 'wsjs.saic.gov.cn',
       'Upgrade-Insecure-Requests': '1',
       'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36',
       'Pragma': 'no-cache',
       'Referer': 'http://wsjs.saic.gov.cn/txnRead01.do?y7bRbp=qmMn0XlK70B26AjTqgIJDr0M1GGWnjtELJdKl9623wVvHTRwH6YL6dPfcEiB_w0kFSbpVKWOvaiuYo.shqXM.PwabTUfgvUh_4sPHcOzFGm2GSJNPChzt5TL4hxSc7R_h9nHqFdlcycITrqs',
       'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
       'Accept-Encoding': 'gzip, deflate',
       'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4',
       'Cache-Control': 'no-cache',
       'Connection': 'keep-alive',
       'Origin':'http://wsjs.saic.gov.cn',	
       'Content-Length':'1399'
       }

with requests.Session() as s:
    res1 = s.get(url1, headers=headers)
    res3 = s.get(url2, headers=headers)
    cookies = dict(res1.cookies)
#print(res1.headers)
    res2 = requests.get(url_f, headers=headers, data=data)
    print(res2.url)
